package com.szeastroc.base.service;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.szeastroc.base.mapper.BaseMapper;


public class BaseServiceImpl<T> implements BaseService<T>{

	protected Logger logger = LoggerFactory.getLogger(getClass());
	
	@Autowired
	protected BaseMapper<T> baseMapper;	

	@Override
	public int insert(T entity) {
		return baseMapper.insert(entity);
	}

	@Override
	public int insertSelective(T entity) {
		return baseMapper.insertSelective(entity);
	}

	@Override
	public void insertList(List<T> list){
		baseMapper.insertList(list);
	}

	@Override
	public int updateByPrimaryKey(T entity) {
		return baseMapper.updateByPrimaryKey(entity);
	}

	@Override
	public int updateByPrimaryKeySelective(T entity) {
		return baseMapper.updateByPrimaryKeySelective(entity);
	}

	@Override
	public int deleteByPrimaryKey(Object primaryKey) {
		return baseMapper.deleteByPrimaryKey(primaryKey);
	}

	@Override
	public int deleteByPrimaryKeys(List<Object> primaryKeys) {
		int resulrt = 0;
		for (Object primaryKey : primaryKeys) {
			resulrt += baseMapper.deleteByPrimaryKey(primaryKey);
		}
		return resulrt;
	}


	@Override
	public T selectOne(T entity) {
		return baseMapper.selectOne(entity);
	}

	@Override
	public T selectByPrimaryKey(Object primaryKey) {
		return baseMapper.selectByPrimaryKey(primaryKey);
	}

	@Override
	public PageInfo<T> selectPage(int pageNum, int pageSize) {
		PageHelper.startPage(pageNum, pageSize);
		List<T> list = baseMapper.selectAll();
		PageInfo<T> page = new PageInfo<T>(list);
		return page;
	}

	@Override
	public List<T> selectAll(){
		return  baseMapper.selectAll();
	}
}


